package com.keenote.ly;

import com.keenote.file.FileUtils;
import org.apache.commons.math3.util.Pair;

import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

/**
 * description
 *
 * @author mic.zhou
 * @date 2022/8/16 18:22
 */
public class VirtualCard {
    public static void main(String[] args) {
        cardType();
//        Set<String> hiveCards = getHiveCards();
//        Set<String> cards = getSdCards();
//        cards.retainAll(hiveCards);
//        List<List<String>> collect = cards.stream().map(Collections::singletonList).collect(Collectors.toList());
//        FileUtils.writeToCsv(collect, "虚拟卡号集合数据_"+System.currentTimeMillis()/1000+".csv");
    }

    private static Set<String> getSdCards() {
        String path = "F:\\OneDrive\\桌面\\cardNo\\虚拟卡号爬虫数据20220802-20220817.xlsx";
        List<List<String>> lists = FileUtils.readExcel(path);
        lists.remove(0);
        lists.remove(0);
        Set<String> cards = lists.stream().map(i -> i.get(0)).collect(Collectors.toSet());
        return cards;
    }

    private static Set<String> getHiveCards() {
        File file = new File("F:\\OneDrive\\桌面\\cardNo\\风控数据");
        Set<String> hiveCards = new HashSet<>();

        for (File path : Objects.requireNonNull(file.listFiles((d, n) -> n.endsWith(".csv")))) {
            List<List<String>> lists = FileUtils.readCsv(path.getAbsolutePath(), true);
            for (List<String> row : lists) {
                //开始和最后一列不要
                for (int j = 1; j < row.size() - 1; j++) {
                    hiveCards.add(row.get(j));
                }
            }
        }
        return hiveCards;
    }

    private static void cardType() {
        File file = new File("F:\\OneDrive\\桌面\\cardNo\\风控数据");
        //sum_pv,member_id,el_memberid_wx,el_memberid_app,tc_33memberid,tc_0memberid,unionid,member_mobile
        String[] title = new String[]{"sum_pv", "member_id", "el_memberid_wx", "el_memberid_app", "tc_33memberid", "tc_0memberid", "unionid", "member_mobile"};
        Map<String, Pair<String,String>> map = new HashMap<>();
        for (File path : Objects.requireNonNull(file.listFiles((d, n) -> n.endsWith(".csv")))) {
            List<List<String>> lists = FileUtils.readCsv(path.getAbsolutePath(), true);
            for (List<String> row : lists) {
                for (int i = 0; i < row.size(); i++) {
                    map.put(row.get(i), new Pair<>(title[i], row.get(6)));
                }
            }
        }
        List<String> cards = FileUtils.readCsvLine("F:\\OneDrive\\桌面\\cardNo\\神盾局&风控卡号交集（确认爬虫、黑名单）20220802-20220817.csv");
        Set<String> collect = cards.stream().filter(map::containsKey).map(i-> map.get(i).getValue()).collect(Collectors.toSet());
        collect.remove("-");
        FileUtils.writeLinesToCsv(new ArrayList<>(collect), "神盾局虚拟卡号分类");

    }

}
